/** 
Copyright (c) 2010, Sheikh Abdul Wahid Ahmed
Details @ http://extremecodeworld.codeplex.com/license
**/

using System;
using System.Data;
using System.Configuration;

/// <summary>
/// Summary description for DateUtil
/// </summary>
namespace EXtremecode.Utils
{
    public class DateUtil
    {
        private static System.Globalization.DateTimeFormatInfo provider;
        private static readonly string dateFormat = Configurations.Provider.DateFormat;
        private static readonly string timeFormat = Configurations.Provider.TimeFormat;

        static DateUtil()
        {
            provider = new System.Globalization.DateTimeFormatInfo();
            provider.ShortDatePattern = dateFormat;
            provider.ShortTimePattern = timeFormat;
            provider.TimeSeparator = Configurations.Provider.TimeSeparator;
            provider.DateSeparator= Configurations.Provider.DateSeparator;
        }
        public static string ToString(DateTime d)
        {
            if (d == DateTime.MinValue) 
                return string.Empty;
            return ((DateTime)d).ToString("d", provider);
        }
        public static string DateTimeToString(DateTime d)
        {
            if (d == DateTime.MinValue)
                return string.Empty;
            return ((DateTime)d).ToString("g", provider);
        }
		public static string GeneralDateTimeToString(DateTime d)
		{
			if (d == DateTime.MinValue)
				return string.Empty;
			return ((DateTime)d).ToString("yyyy/MM/dd/ hh:mm:ss");
		}
		public static string GeneralToString(DateTime d)
		{
			if (d == DateTime.MinValue)
				return string.Empty;
			return ((DateTime)d).ToString("yyyy/MM/dd");
		}
        public static DateTime ToDate(string strDate)
        {
            return DateTime.ParseExact(strDate, "d", provider);
        }
		public static DateTime GeneralToDate(string strDate)
		{
			return DateTime.ParseExact(strDate, "yyyy/MM/dd", provider);
		}
		public static DateTime GeneralToDateTime(string strDateTime)
		{
			return DateTime.ParseExact(strDateTime, "yyyy/MM/dd hh:mm:ss", provider);
		}
	
		public static DateTime ToDateTime(string strDateTime)
		{
			return DateTime.ParseExact(strDateTime, "g", provider);
		}

		public static string DateFormat
		{
			get
			{
				return dateFormat;
			}
		}
    }
}